$(document).ready(function(){
    var index;
    $('#banner .layout_panel .layout .main-content .tabs-head>a').click(function(){
        index = $(this).index();
        $(this).addClass('now').siblings().removeClass("now");
        if(index == 0){
            $(this).parent().parent().children().eq(index+1).css('display','block').next().css('display','none');
        }else {
            $(this).parent().parent().children().eq(index).css('display','block').prev().css('display','none');
        }
    });

    $('#login-button').click(function(){
        $('#username').css('border','1px solid #e0e0e0');
        $('#pwd').css('border','1px solid #e0e0e0');
        $('#username').parent().next().css('display','none');
        $.ajax({
            type: "POST", 
            url: "./php/login.php",  
            data: {
                'username':$('#username').val(),
                'password':$('#pwd').val()
            }, 
            dataType: "json",
            success: function (res) { 
                var {status,meta:{msg,data}} = res;
                if(status == 0){

                    $('#username').css('border','1px solid #f56600');
                    $('#username').parent().next().css('display','block');
                    layer.msg()
                }else if(status == 2){

                    $('#pwd').css('border','1px solid #f56600');
                    $('#pwd').parent().next().css('display','block');

                }else if(status == 1){
                    layer.msg(msg,{
                        icon:1,
                        time:1500
                    },function(){
                        tool.setCookie('username',data, 7*1000*60*60);
                        var url = localStorage.getItem('url')
                        if(url){
                            // 清空本地存储中的url
                            localStorage.removeItem('url');
                            window.location.href = url;
                        }else{
                            window.location.href = './index.html';
                        }
                    });
                    
                }
            }
        });
    });
});